package com.hao.hospital.util;


import com.hao.hospital.core.param.GlobalMap;
import com.hao.hospital.weixin.api.WeiXinAPI;
import com.hao.hospital.weixin.menu.Button;
import com.hao.hospital.weixin.menu.Menu;
import com.hao.hospital.weixin.menu.ViewButton;
import com.jfinal.aop.Enhancer;
import com.jfinal.kit.PropKit;

public class WeiXinUtil {
	private static WeiXinUtil me;
	
	public static WeiXinUtil me() {
		if (null == me) {
			me = Enhancer.enhance(WeiXinUtil.class);
		}
		return me;
	}
	/**
	 * 组装菜单参数
	 * @return
	 */
	public Menu initMenu(){
		Menu menu=new Menu();
		String url=GlobalMap.configMap.get("domain").toString();
		ViewButton OnlineBooking=new ViewButton();
		OnlineBooking.setName("在线预约");
		OnlineBooking.setType("view");
		OnlineBooking.setUrl(url+"/OnlineBooking");
//		ViewButton MedicalQuiry=new ViewButton();
//		MedicalQuiry.setName("病历查询");
//		MedicalQuiry.setType("view");
//		MedicalQuiry.setUrl(url+"/MedicalQuiry");
		ViewButton PatientPayment=new ViewButton();
		PatientPayment.setName("个人中心");
		PatientPayment.setType("view");
		PatientPayment.setUrl(url+"/PatientPayment");
		menu.setButton(new Button[]{OnlineBooking,PatientPayment});
		return menu;
	}
	/**
	 * 初始化token Url
	 * @return
	 */
	public String initTokenURl(){
		String appid=PropKit.get("appid");
		String appsecret=PropKit.get("appsecret");
		return WeiXinAPI.GetAccessToken(appid, appsecret);
	}
	/**
	 * 初始化code Url
	 * @return
	 */
	public String initCodeURL(){
		String appid=GlobalMap.configMap.get("appid").toString();
		String redirectUri=GlobalMap.configMap.get("redirectUri").toString();
		String scope=GlobalMap.configMap.get("scope").toString();
		return WeiXinAPI.GetCode(appid, redirectUri, scope);
	}
	/**
	 * 获取 User accessToken(获取用户相关接口的凭证)
	 * @param code
	 * @return
	 */
	public String initUserTokenURL(String code){
		String appid=GlobalMap.configMap.get("appid").toString();
		String secret=GlobalMap.configMap.get("appsecret").toString();
		return WeiXinAPI.GetUserAccessToken(appid, secret, code);
	}
	/**
	 * 获取 User Info(拉取信息)
	 * @param accessToken
	 * @param openid
	 * @return
	 */
	public String initUserInfoURL(String accessToken,String openid){
		return WeiXinAPI.GetUserInfo(accessToken, openid);
	}
}
